import 'package:flutter/material.dart';

class BlockWidget extends StatelessWidget {
  final Widget? title;
  final Widget child;
  final Widget? footer;
  final EdgeInsetsGeometry? margin;
  final EdgeInsetsGeometry? padding;
  final Color? color;
  final BoxDecoration? decoration;
  final Divider divider;

  const BlockWidget({
    Key? key,
    this.title,
    required this.child,
    this.footer,
    this.margin,
    this.padding,
    this.color,
    this.decoration,
    this.divider = const Divider(
      thickness: 0.5,
      height: 1,
      color: Colors.black26,
    ),
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: margin,
      padding: padding,
      color: color,
      decoration: decoration,
      child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            if (title != null) title!,
            if (title != null) divider,
            child,
            if (footer != null) divider,
            if (footer != null) footer!,
          ]),
    );
  }
}

class BlockTitle extends StatelessWidget {
  final Widget title;
  final Widget? leading;
  final List<Widget>? actions;
  final EdgeInsetsGeometry? padding;

  const BlockTitle({
    Key? key,
    required this.title,
    this.leading,
    this.actions,
    this.padding = const EdgeInsets.symmetric(vertical: 8, horizontal: 15),
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: padding,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          if (leading != null) leading!,
          Expanded(
              child: DefaultTextStyle(
                  style: Theme.of(context).textTheme.bodyText1!, child: title)),
          if (actions != null) ...actions!,
        ],
      ),
    );
  }
}
